package cn.supermarket;


import cn.supermarket.mapper.RefundMapper;
import cn.supermarket.pojo.vo.RefundDetailsVO;
import cn.supermarket.utils.SnowFlakeGenerateIdWorker;
import cn.supermarket.utils.easyExcel;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.SocketException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.*;
import java.util.Date;
import java.util.List;

@SpringBootTest
public class test {

    @Autowired
    easyExcel excel;

    @Autowired
    RefundMapper refundMapper;


    @Test
    void test1() throws ParseException {


        SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");
        Date date1 = dateformat.parse("2016-5-12");
        System.out.println("date1 = " + date1);

        Instant instant = date1.toInstant();
        ZoneId zoneId = ZoneId.systemDefault();

        // atZone()方法返回在指定时区从此Instant生成的ZonedDateTime。
        LocalDate localDate = instant.atZone(zoneId).toLocalDate();
        LocalDateTime localDateTime = localDate.atStartOfDay();
        System.out.println("localDateTime = " + localDateTime);
        LocalDateTime end = localDateTime.plusDays(1);
        System.out.println("end = " + end);
    }

    @Test
    void text2() {
        List<RefundDetailsVO> list = refundMapper.selectBySupplier("甲");
        excel.writeExcelAll(list, "excel.xlsx", "退款信息");
    }

    @Test
    void text3() throws SocketException, InterruptedException {
        for(int i = 0;i <10000;i++) {
            SnowFlakeGenerateIdWorker snowFlake = new SnowFlakeGenerateIdWorker(15L,20L);
            Thread.sleep(1);
                Long id = snowFlake.nextId();
            System.out.println("id = " + id);
            //id = 988728854424645632
        }
    }
}


